home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group97b.txt / 000017_icon-group-sender _Wed Jul 9 11:12:07 1997.msg < prev    next >
Internet Message Format  |  2000-09-20  |  1KB

  1. Received: from kingfisher.CS.Arizona.EDU by cheltenham.cs.arizona.edu; Wed, 9 Jul 1997 12:27:03 MST
  2. Received: by kingfisher.CS.Arizona.EDU; (5.65v3.2/1.1.8.2/08Nov94-0446PM)
  3.     id AA25461; Wed, 9 Jul 1997 12:27:03 -0700
  4. Date: Wed, 9 Jul 1997 11:12:07 -0500 (CDT)
  5. Message-Id: <199707091612.LAA21200@dfw-ix5.ix.netcom.com>
  6. X-Sender: bobalex@popd.ix.netcom.com
  7. X-Mailer: Windows Eudora Pro Version 2.1.2
  8. Mime-Version: 1.0
  9. Content-Type: text/plain; charset="us-ascii"
  10. To: Icon Group <icon-group@cs.arizona.edu>
  11. From: Bob Alexander <bobalex@ix.netcom.com>
  12. Subject: Re: A small puzzle
  13. Errors-To: icon-group-errors@cs.arizona.edu
  14. Status: RO
  15.  
  16. This is a really BORING solution, 'cause it's terribly straightforward, and
  17. probably the same way someone would do it in C, but why not:
  18.  
  19.   procedure lcp(a,b)
  20.     every i := seq() do
  21.       if not (a[i] == b[i]) then
  22.         return a[1:i]
  23.   end
  24.  
  25. Or, maybe more efficient but less transparent:
  26.  
  27.   procedure lcp(a,b)
  28.     every i := seq() do
  29.       if not match(a[i],b,i) then
  30.         return a[1:i]
  31.   end
  32.  
  33. ?
  34.  
  35. Seems to me that this approach is linear in terms of characters examined
  36. (where n is somehow related to the lengths of the strings involved), as
  37. opposed to several n-squared agorithms I've seen here and in the SNOBOL4 area.
  38.  
  39. -- Bob
  40.  
  41.